<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<title>专业词汇</title>
		<link rel="stylesheet" href="/mobile/layui/css/layui.css" />
		<link rel="stylesheet" href="/mobile/css/mobile.css" />
		<script src="/mobile/js/jquery.min.js"></script>
		<script src="/mobile/js/jquery.easing.min.js"></script>
		<script src="/mobile/layui/layui.js"></script>

	</head>
	<body>

		<img src="{$banner.image}" style="width: 100%; height: auto;">
		<div class="main" style="position: relative;">
			<div class="search_container" style="margin:0 0 15px;background: #fff;border:1px solid #e5e5e5;">
				<input type="search" onkey class="search" style="background: #fff;"  placeholder="仅支持橡塑技术与装备行业专业词汇中英文翻译"  />
			</div>
			<ul class="sousuotuijian">

			</ul>
			<div id="ajax_result">

			</div>
			<img src="/mobile/img/bg_cihui.jpg" style="width: 100%; height: auto;" />
		</div>
		{include file="common/footer"}
	</body>
	<script type="text/javascript">

		$("input.search").keypress(function (e) {
		    	// 兼容写法
		      e = e || window.event;
		      key = e.keyCode || e.which || e.charCode;
		      if (key == 13) {
		          console.log($(this).val());
				  if($(this).val().trim()==''){
					  alert('请输入关键词');
					  return false;
				  }
				  window.open('{:url('cihui/fanyi')}?keyword='+$(this).val(),'_blank')
		      }
		  });
		  $('input.search').bind('input propertychange', function(){
			  if($(this).val().trim()!=""){
				  $.ajax({
				      type:"GET",
				      url:"/api.php/index/get_cihui",
				      dataType:"json",
				      data:{
				          "keyword":$(this).val(),
				      },
				      success:function(res){
				        console.log(res.data);
				  					html='';
				  					for( var i in res.data){
				  						html+='<li onclick="gosearch(this)">'+res.data[i].word+'</li>';
				  					}
				        $('.sousuotuijian').html(html);
				      }
				  });
			  }else{
				  $('.sousuotuijian').html('');
			  }

		  })

		function gosearch(e){
			var keyword=$(e).text();
			$.ajax({
				type:"GET",
				url:"{:url('cihui/ajax_fanyi')}",
				dataType:"json",
				data:{
					"keyword":keyword,
				},
				success:function(res){
					console.log(res);
					$('.sousuotuijian').html('');
					if(res.code==1){
						html='<div class="fanyi_result">'+
								'<ul>'+
								'<li><label>词汇：</label>'+res.data.word+'</li>'+
								'<li><label>解释：</label>'+res.data.explains+'</li>'+
								'<li><label>拼音：</label>'+res.data.py+'</li>'+
								'</ul>'+
								'</div>';
					}else{
						html='<div class="empty">'+
								'<div>'+
								'<img src="/mobile/img/ico_empty.png" >'+
								'<p>没有查询到对应内容</p>'+
								'</div>'+
								'</div>';
					}
					$('#ajax_result').html(html);
				}
			});
		}


		  function gosearch2(e){
			  var keyword=$(e).text();
			  window.open('{:url('cihui/fanyi')}?keyword='+keyword,'_blank')
		  }
	</script>
</html>
